/**
 * ReportGear(2011)
 */
package com.reportgear.designer.action.edit;

import java.awt.event.ActionEvent;

import net.abbp.report.context.ReportContext;
import net.abbp.report.model.ReportModel;
import net.abbp.report.view.GridView;
import net.abbp.report.view.grid.Grid;

import com.reportgear.designer.action.ReportAction;
import com.reportgear.report.view.grid.selection.GridSelection;
import com.reportgear.report.view.grid.selection.Selection;

/**
 * 清除单元格内容Action
 * 
 * @version 1.0 2011-6-13
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since Report 1.0
 */
public class ClearValueAction extends ReportAction {
    public ClearValueAction() {
        this.setName("清除单元格");
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        GridView gridView = ReportContext.INSTANCE.getCurrentView();
        if (gridView == null) {
            return;
        }

        GridSelection gridSel = gridView.getGridSelection();
        Grid grid = gridView.getGrid();
        if (grid.isCellSelectable()) {
            try {
                Selection sel = gridSel.getEditSelection();
                ReportModel report = gridView.getReportModel();

                // 改为Remove
                report.setCellValue(sel, "");

                // TODO 确认这儿更新
                gridView.refresh();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
}
